package com.hhit.bigscreenbackmanage.common;

import java.util.List;

/**
 * 分页类
 *
 * @author Lenovo
 *
 */
public class PageUtil<T> {
    private Integer pageNum;// 当前的页码
    private Integer totalCount;// 总条数，总记录数
    private Integer totalPage;// 总页数
    public  Integer pageCount = 8;// 每页8条
    private Integer rowNum;// 当前页起始行号
    private List<T> list;// 当前页的内容
    private List<String> chartList;

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > totalPage) {
            pageNum = totalPage;
        }
        if (totalPage == 0) {
            pageNum = 1;
        }
        this.pageNum = pageNum;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage() {
        if (totalCount % pageCount == 0) {
            this.totalPage = totalCount / pageCount;
        } else {
            this.totalPage = totalCount / pageCount + 1;
        }
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getRowNum() {
        return rowNum;
    }

    public void setRowNum() {
        this.rowNum = (pageNum - 1) * pageCount;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public List<String> getChartList() {
        return chartList;
    }

    public void setChartList(List<String> chartList) {
        this.chartList = chartList;
    }

    @Override
    public String toString() {
        return "Page [pageNum=" + pageNum + ", totalCount=" + totalCount + ", totalPage=" + totalPage + ", rowNum="
                + rowNum + ", list=" + list + ", chartList=" + chartList + "]";
    }

    public void init(Integer totalCount, Integer pageNum) {
        setTotalCount(totalCount);
        setTotalPage();
        setPageNum(pageNum);
        setRowNum();
    }
}
